<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<table border="1" cellspacing="0" cellpadding="10px" id='t_Id'>
			<tr>
				<th></th>
				<th>姓名</th>
				<th>性别</th>
				<th>年龄</th>
				<th>家庭住址</th>
			</tr>
			<tr>	
				<td><input type="checkbox" name="stu" id="" value="nan" /></td>
				<td>张三</td>
				<td>男</td>
				<td>19</td>
				<td>福建省新罗区</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="stu" id="" value="nv" /></td>
				<td>李四</td>
				<td>女</td>
				<td>19</td>
				<td>福建省新罗区</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="stu" id="" value="nan" /></td>
				<td>王五</td>
				<td>男</td>
				<td>19</td>
				<td>福建省新罗区</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="stu" id="" value="nan" /></td>
				<td>赵六</td>
				<td>男</td>
				<td>19</td>
				<td>福建省新罗区</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="stu" id="" value="nv" /></td>
				<td>小黄</td>
				<td>女</td>
				<td>19</td>
				<td>福建省新罗区</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="stu" id="" value="nv" /></td>
				<td>小鸡</td>
				<td>女</td>
				<td>19</td>
				<td>福建省新罗区</td>
			</tr>
		</table>
		<td><input type="checkbox" name="" id="input_1" value="" onclick="add();" /></td>全选
		<td><input type="checkbox" name="" id="input_2" value="" onclick="ppd();" /></td>全选男
		<td><input type="checkbox" name="" id="input_3" value="" onclick="AGchw();" /></td>全选女
	</body>
	<script type="text/javascript">
		var t_idobj=document.getElementById('t_Id')
		var all_input=t_idobj.getElementsByTagName('input')		

		function add(){
			var iptvalue=document.getElementById('input_1')	
			for (var i = 0; i < all_input.length; i++) {
				all_input[i].checked=iptvalue.checked
			}
		}
		
		function ppd(){
			var checkbox_nan = document.getElementById('input_2')
			for (var i = 0; i < all_input.length; i++) {
				if ( all_input[i].value =='nan') {
					all_input[i].checked=checkbox_nan.checked
				} 
			}
		}
		
		function AGchw(){
			var checkbox_nv = document.getElementById('input_3')
			for (var i = 0; i < all_input.length; i++) {
				if ( all_input[i].value =='nv') {
					all_input[i].checked=checkbox_nv.checked
				} 
			}
		}
	</script>
</html>
